package org.example.pool;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutionException;

public class MyRunnable implements Runnable{
    private Runnable nextTask;
    private char c;



    public char getC() {
        return c;
    }

    public void setC(char c) {
        this.c = c;
    }

    public Runnable getNextTask() {
        return nextTask;
    }

    public void setNextTask(Runnable nextTask) {
        this.nextTask = nextTask;
    }

    public MyRunnable(Runnable nextTask, char c) {
        this.nextTask = nextTask;
        this.c = c;
    }

    public MyRunnable(char c) {
        this.c = c;
    }

    @Override
    public void run() {
        for(int i=1;i<=100;i++){
            try {
                synchronized (this) {
                    this.wait();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName()+"线程，打印了第"+i+"个："+c);
            synchronized (nextTask){
                nextTask.notify();
            }
        }
    }


    public static void main(String[] args)  {
        MyRunnable a = new MyRunnable('A');
        MyRunnable c = new MyRunnable(a,'C');
        MyRunnable b = new MyRunnable(c,'B');
        a.setNextTask(b);
        Thread t1 = new Thread(a);
        Thread t2 = new Thread(b);
        Thread t3 = new Thread(c);
        t1.start();
        t2.start();
        t3.start();
    }
}
